﻿#region Using Statements
using System;
#endregion

namespace DirectZZT.Shared.World.Objects
{
    /// <summary>
    /// Attribute to describe <see cref="BoardObject"/>s.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
    public sealed class BoardObjectAttribute : Attribute
    {
        #region Properties

        /// <summary>
        /// Gets/sets the identifier of this board object. This should be unique.
        /// </summary>
        public string Identifier { get; set; }
        /// <summary>
        /// Gets/sets whether to serialize this board object.
        /// See documentation for further information.
        /// </summary>
        /// <remarks>The default value of this property is <c>true</c>.</remarks>
        public bool Serialize { get; set; }
        /// <summary>
        /// Gets/sets whether or not the "BecomeObject" command is allowed for this object,
        /// enabling other objects to "become" this board object.
        /// See documentation for further information.
        /// </summary>
        /// <remarks>The default value of this property is <c>true</c>.</remarks>
        public bool AllowBecome { get; set; }
        /// <summary>
        /// Gets/sets the classification of this BoardObject.
        /// </summary>
        public BoardObjectClassification Classification { get; set; }

        #endregion

        #region Constructors
        
        /// <summary>
        /// Initializes a new instance of the BoardObjectAttribute class.
        /// </summary>
        public BoardObjectAttribute()
        {
            this.Serialize = true;
            this.AllowBecome = true;
        }

        #endregion

        #region Static methods

        /// <summary>
        /// Attempts to return the <see cref="BoardObjectAttribute"/> from the given type.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static BoardObjectAttribute GetAttribute(Type type)
        {
            BoardObjectAttribute[] attributes = type.GetCustomAttributes(typeof(BoardObjectAttribute), false) as BoardObjectAttribute[];
            if (attributes != null && attributes.Length == 1)
            {
                return attributes[0];
            }
            return null;
        }

        #endregion

    }
}
